package escom.dds.gestionarmateria.dao;

import java.util.List;

import javax.inject.Named;

import org.springframework.orm.hibernate4.support.HibernateDaoSupport;

import escom.dds.modelo.Materia;

@Named("materiaDao")
public class MateriaDao extends HibernateDaoSupport {
	
	public Materia save(Materia materia){
		Materia materiaAux = getHibernateTemplate().merge(materia);
		getHibernateTemplate().save(materiaAux);
		return materiaAux;
	}
	
	public Materia findById(Materia materia) {
		return getHibernateTemplate().get(Materia.class, materia.getId());
	}
	
	public Materia update(Materia materia){
		Materia materiaAux = getHibernateTemplate().merge(materia);
		getHibernateTemplate().update(materiaAux);
		return materiaAux;
	}
	
	public List<Materia> findAll(){
		return getHibernateTemplate().loadAll(Materia.class);
	}

}
